//
//  TestView.m
//  MVCTest
//
//  Created by Noah on 2017/5/19.
//  Copyright © 2017年 Noah. All rights reserved.
//

#import "TestView.h"

@interface TestView ()

@property (strong,nonatomic)UIButton *editBtn;
@property (strong,nonatomic)UIButton *saveBtn;

@end



@implementation TestView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _editBtn = [[UIButton alloc]init];
        [_editBtn setFrame:CGRectMake(0, 0, frame.size.width/2, frame.size.height/2)];
        [_editBtn setTitle:@"编辑" forState:UIControlStateNormal];
        [_editBtn.titleLabel setFont:[UIFont systemFontOfSize:18]];
        [_editBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_editBtn addTarget:self action:@selector(edit) forControlEvents:UIControlEventTouchUpInside];
        _saveBtn = [[UIButton alloc]init];
        [_saveBtn setFrame:CGRectMake(frame.size.width/2, 0, frame.size.width/2, frame.size.height/2)];
        [_saveBtn setTitle:@"保存" forState:UIControlStateNormal];
        [_saveBtn.titleLabel setFont:[UIFont systemFontOfSize:18]];
        [_saveBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:_editBtn];
        [self addSubview:_saveBtn];
        UILabel *label = [[UILabel alloc]init];
        [label setFrame:CGRectMake(0, self.frame.size.height/2, self.frame.size.width, self.frame.size.height/2)];
        label.tag = 88;
        label.numberOfLines = 0;
        [self addSubview:label];
    }
    return self;
}

-(void)showMessage:(NSDictionary*)dic{
    UILabel *label = [self viewWithTag:88];
    label.text = [NSString stringWithFormat:@"姓名：%@,性别：%@，message：%@",[dic objectForKey:@"name"],[dic objectForKey:@"sex"],[dic objectForKey:@"text"]];
    
}
#pragma mark ------TestViewDelegate-------
-(void)edit{
    if ([self.delegate respondsToSelector:@selector(editMessageWithTestView:)]) {
        [self.delegate editMessageWithTestView:self];
    }
}
-(void)save{
    if ([self.delegate respondsToSelector:@selector(saveMessageWithTestView:)]) {
        [self.delegate saveMessageWithTestView:self];
    }
}


@end
